//
// Created by Felix on 24-4-27.
//

#include "ErrorHandler.hpp"

std::shared_ptr<ErrorHandler::OutgoingResponse> ErrorHandler::handleError(
        const Status &status, const oatpp::String &message, const Headers &headers
) {
    auto error = MessageDto<>::createShared();
    error->status = "ERROR";
    error->statusCode = status.code;
    error->message = message;
    error->data = oatpp::List<oatpp::Any>({});

    auto response = ResponseFactory::createResponse(status, error, iObjectMapper);

    for (const auto &pair: headers.getAll()) {
        response->putHeader(pair.first.toString(), pair.second.toString());
    }

    return response;
}
